package com.yyk.yiliao.ui.mine.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hyphenate.chat.EMClient;
import com.orhanobut.hawk.Hawk;
import com.yyk.yiliao.R;
import com.yyk.yiliao.base.BaseActivity;
import com.yyk.yiliao.listener.DialogSureCancelListenter;
import com.yyk.yiliao.ui.Main_Activity;
import com.yyk.yiliao.ui.gongyong.activity.WebViewActivity;
import com.yyk.yiliao.ui.mine.APKVersionCodeUtils;
import com.yyk.yiliao.ui.trade.minepwd.SafeSetActivity;
import com.yyk.yiliao.util.DialogUtil;
import com.yyk.yiliao.util.ToastUtil;
import com.yyk.yiliao.util.rx.ApiService;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 设置
 */
public class Set_Activity extends BaseActivity {
    @BindView(R.id.nSet_one) //密码设置
            RelativeLayout nSetOne;
    @BindView(R.id.mSet_two) //消息提醒设置
            RelativeLayout mSetTwo;
    @BindView(R.id.mSet_three) //收获地址管理
            RelativeLayout mSetThree;
    @BindView(R.id.mSet_four) //使用帮助
            RelativeLayout mSetFour;
    @BindView(R.id.mSet_five)//立即分享
            RelativeLayout mSetFive;
    @BindView(R.id.mSet_six)//关于我们
            RelativeLayout mSetSix;
    @BindView(R.id.nSet_eight) //清除本地缓存
            RelativeLayout nSetEight;

    @BindView(R.id.tv_huancun)//本地缓存文字
            TextView tvHuancun;
    @BindView(R.id.mSet_exit)
    Button mSetExit;

    @BindView(R.id.tv_apkversion)
    TextView tvApkversion;


    @Override
    public int getLayoutId() {
        return R.layout.activity_set;
    }

    @Override
    public void initView() {
        initToolbar();

    }

    private void initToolbar() {
        setBackArrow();
        setTitle("设置");
    }

    @Override
    public void initData() {
        tvApkversion.setText("版本号 "+APKVersionCodeUtils.getVerName(mActivity));
    }

    /**
     * 1.
     * 2.
     * 3.收货地址管理
     * 4.使用帮助
     * 5.立即分享
     * 6.关于我们
     * <p>
     * 7.
     * 8.清除本地缓存
     * 9.退出登录
     *
     * @param view
     */
    @OnClick({R.id.nSet_one, R.id.mSet_two, R.id.mSet_three, R.id.mSet_four, R.id.mSet_five, R.id.mSet_six, R.id.nSet_eight, R.id.mSet_exit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.nSet_one:
                startAct(SafeSetActivity.class);

                break;
            case R.id.mSet_two:

                break;
            case R.id.mSet_three:

                startAct(ShAdressGl2_Activity.class);
                break;
            case R.id.mSet_four:
                startAct(Usehelp_Activity.class);
                break;
            case R.id.mSet_five:
                Intent mSet_five = new Intent();
                mSet_five.putExtra("toolbar_tv", "云医康");
                mSet_five.putExtra("url", ApiService.H5_URL_SHARE + "&Sources=3");
                startAct(mSet_five, WebViewActivity.class, null);
                break;
            case R.id.mSet_six:
                Intent mSet_six = new Intent(Set_Activity.this, Aboutus_Activity.class);
                startActivity(mSet_six);
                break;

            case R.id.nSet_eight:
                DialogUtil.getIntanse().showReturnTips(mActivity, null, "是否清除本地缓存", "确定", "取消", new DialogSureCancelListenter() {
                    @Override
                    public void onSureListenter() {
                        tvHuancun.setText("0.0KB");
                        ToastUtil.showShort(Set_Activity.this, "本地缓存清除成功");
                    }
                    @Override
                    public void onCancelListenter() {

                    }
                }, false);
                break;
            case R.id.mSet_exit:
                DialogUtil.getIntanse().showReturnTips(mActivity, null, "是否退出当前账户", "确定", "取消", new DialogSureCancelListenter() {
                    @Override
                    public void onSureListenter() {
                        Hawk.delete("uid");
                        Hawk.delete("real");
                        Hawk.delete("statusfo"); //鲁亿通
                        Hawk.delete("real_name");//姓名
                        Hawk.delete("phone");//手机号
                        if (Hawk.contains("wxpic")) {
                            Hawk.delete("wxpic");//删除微信图片
                        }
                        //退出环信账号
                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                //被T的情况下
                                EMClient.getInstance().logout(true);
                            }
                        }).start();
                        Intent intent = new Intent();
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                        finish();
                        startAct(intent, Main_Activity.class, null);
                        ToastUtil.showShort(Set_Activity.this, "退出成功");
                    }

                    @Override
                    public void onCancelListenter() {

                    }
                }, false);
                break;
        }
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
